<html>
<head>
<link rel="stylesheet" href="./../style/style.css">
</head>
<body>
<?php
session_start();
if (isset($_SESSION['username']))
{
  $id = mysql_connect($db_host,$db_usr,$db_pass) or die('Could not connect: ' . mysql_error());;
  mysql_select_db($db_name);
  $res = mysql_query("SELECT * FROM $db_name");
  
  $i = 0;
  $a=array();

  echo "<table align='center' cellspacing='30'>
  <tr>
  ";

echo "<a href='add.php'>Add new photo</a> <br>";
while($obj = mysql_fetch_object($res))
{
    if ($i == $sirka_gal) //Ak sa poradie obrazkov rovne sirka gallerie, dopise sa do dalsieho riadku tabulky ich popisy a vynuli sa citac i
    {
      echo "</tr>
      <tr>
      ";
      
      foreach ($a as $value)
      {
        echo "<td>".$value." <a href='del.php?id=$obj->id&f=$obj->link'>Delete</a> <a href='update.php?id=$obj->id'>Update</a></td>
        ";
      }
      
      echo "</tr>
      <tr>";
      $a=array();
      $i=0;
    }
    
    echo "<td><a href='images/gallery/".$obj->link."' target='_blank'><img src='images/gallery/thumbnails/".$obj->link."' border=0></a></td>
    ";
    $s = $obj->name;
    array_push($a,$s);
    $i++;
}
foreach ($a as $value)
{
echo "<td>".$value." <a href='del.php?id=$obj->id'>Delete</a></td>
";
}

for ($j = $i; $j < $sirka_gal; $j++){
echo "<td>&nbsp;</td>
";
}

echo "</tr>
</table>
";

for ($i=1; $i<=(($rows/$poc_obr) + 1); $i++) //Vygeneruje linky na strany.
{
	 echo "<a href='gallery.php?page=".$i."'>".$i."</a>&nbsp;";
}

mysql_close($id);
  
}
else
{
header("location:index.php");
exit;
}
?>
</body>
</html>